//
//  TestbedLayer.m
//  ChipmunkEditor
//
//  Created by Rewolf Us on 11-2-3.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TestbedLayer.h"
#import "cmTypes.h"
#import "SpaceManagerCocos2d.h"
#import "AppController.h"

@implementation TestbedLayer
@synthesize isEngineRunning;

+ (id)scene{
	CCScene *scene=[CCScene node];
	TestbedLayer *layer=[TestbedLayer node];
	[scene addChild:layer];
	return scene;
}

- (id) init{
	if ((self=[super init])) {
		smgr=[[SpaceManagerCocos2d alloc] init];
		smgr.constantDt=1/60.0;
		[smgr addWindowContainmentWithFriction:1.0 elasticity:1.0 inset:cpvzero];
		[self addChild:[smgr createDebugLayer]];
		NSLog(@"%@",[AppController sharedAppcontroller]);
		[[AppController sharedAppcontroller] setTestbedLayerDelegate:self];
		isEngineRunning=NO;
	}
	return self;
}

-(void)addACircle:(CmCircle*)aCircle{
	cpShape *shape=[smgr addCircleAt:aCircle.pos mass:aCircle.mass radius:aCircle.radius];
	cpShapeNode *node=[cpShapeNode nodeWithShape:shape];
	node.color=ccc3(255, 255, 0);
	[self addChild:node];
	//debug output
}

-(void)startEngine{
	isEngineRunning=YES;
	[smgr start];
}

-(void)stopEngine{
	isEngineRunning=NO;
	[smgr stop];
}

@end
